﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KKU.RBSFPP.Shared.DAC;

namespace KKU.RBSFPP.Web.Administrator.Controllers
{
    public class FactorAllController : Controller
    {
        private RBSFPPModelContainer db = new RBSFPPModelContainer();

        //
        // GET: /FactorAll/

        public ActionResult Index()
        {
            return View(db.Factors.ToList());
        }

        //
        // GET: /FactorAll/Details/5

        public ActionResult Details(int id = 0)
        {
            Factor factor = db.Factors.Single(f => f.FactorId == id);
            if (factor == null)
            {
                return HttpNotFound();
            }
            return View(factor);
        }

        //
        // GET: /FactorAll/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /FactorAll/Create

        [HttpPost]
        public ActionResult Create(Factor factor)
        {
            if (ModelState.IsValid)
            {
                db.Factors.AddObject(factor);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(factor);
        }

        //
        // GET: /FactorAll/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Factor factor = db.Factors.Single(f => f.FactorId == id);
            if (factor == null)
            {
                return HttpNotFound();
            }
            return View(factor);
        }

        //
        // POST: /FactorAll/Edit/5

        [HttpPost]
        public ActionResult Edit(Factor factor)
        {
            if (ModelState.IsValid)
            {
                db.Factors.Attach(factor);
                db.ObjectStateManager.ChangeObjectState(factor, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(factor);
        }

        //
        // GET: /FactorAll/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Factor factor = db.Factors.Single(f => f.FactorId == id);
            if (factor == null)
            {
                return HttpNotFound();
            }
            return View(factor);
        }

        //
        // POST: /FactorAll/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Factor factor = db.Factors.Single(f => f.FactorId == id);
            db.Factors.DeleteObject(factor);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}